package com.shct10000.controller;


import com.shct10000.common.Result;
import com.shct10000.entity.Customer;
import com.shct10000.exception.CustomException;
import com.shct10000.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class WebController {
    @GetMapping("/hello")
    public String index(){
        return "Hello World";
    }
    @GetMapping("/weather")
    public String weather(){
        return "今天天气36u";
    }
    @GetMapping("/count")
    public Result count (){
            throw new CustomException(400,"错误！禁止请求");
//        int a= 1/0;
//        return Result.success(10);
    }

    @GetMapping("/map")
    public Result map(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("name","maco");
        map.put("age","18");
        return  Result.success(map);
    }
    @Resource
    private CustomerService customerService;
    @GetMapping("/sql")
    public Result sql(){
        try {
            List<Customer> list = customerService.selectALL();
            return Result.success(list.size());
        } catch (Exception e) {
            return Result.err(e);
        }
    }


}

